home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / wmapdemo / data.z / PREVIEW.PAS < prev    next >
Pascal/Delphi Source File  |  1996-03-09  |  3KB  |  117 lines

  1. unit Preview;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes,
  7.   Graphics, Controls, Forms, Dialogs, ExtCtrls,
  8.   Buttons, Printers, StdCtrls;
  9.  
  10. type
  11.   TPreviewForm = class(TForm)
  12.     Panel1: TPanel;
  13.     ScalePlusButton: TSpeedButton;
  14.     ScaleMinusButton: TSpeedButton;
  15.     PrintButton: TSpeedButton;
  16.     ScrollBox1: TScrollBox;
  17.     Image1: TImage;
  18.     CancelButton: TSpeedButton;
  19.     Label1: TLabel;
  20.     procedure ScalePlusButtonClick(Sender: TObject);
  21.     procedure ScaleMinusButtonClick(Sender: TObject);
  22.     procedure CancelButtonClick(Sender: TObject);
  23.     procedure PrintButtonClick(Sender: TObject);
  24.   public
  25.     Scale: Integer;
  26.     procedure DrawPreview;
  27.     procedure SetPage;
  28.   end;
  29.  
  30. var
  31.   PreviewForm: TPreviewForm;
  32.  
  33. implementation
  34.  
  35. {$R *.DFM}
  36.  
  37. uses
  38.   Viewer;
  39.  
  40. procedure TPreviewForm.SetPage;
  41. begin
  42.   {set the image size to be proportional with the page size}
  43.   Image1.Width := Printer.PageWidth div 5;
  44.   Image1.Height := Printer.PageHeight div 5;
  45.   {output the scale to the toolbar}
  46.   Label1.Caption := IntToStr (Scale);
  47. end;
  48.  
  49. procedure TPreviewForm.ScalePlusButtonClick(Sender: TObject);
  50. begin
  51.   {increse the size of the bitmap}
  52.   Scale := Scale * 2;
  53.   Label1.Caption := IntToStr (Scale);
  54.   DrawPreview;
  55. end;
  56.  
  57. procedure TPreviewForm.DrawPreview;
  58. var
  59.   Rect: TRect;
  60. begin
  61.   {compute the rectangle for the bitmap preview}
  62.   Rect.Top := 10;
  63.   Rect.Left := 10;
  64.   Rect.Right := 10 +
  65.     (BMPShow.Image1.Picture.Graphic.Width * Scale) div 5;
  66.   Rect.Bottom := 10 +
  67.     (BMPShow.Image1.Picture.Graphic.Height * Scale) div 5;
  68.  
  69.   {remove the current image}
  70.   Image1.Canvas.Pen.Mode := pmWhite;
  71.   Image1.Canvas.Rectangle (0, 0, Image1.Width, Image1.Height);
  72.  
  73.   {stretch the bitmap into the rectangle}
  74.   Image1.Canvas.StretchDraw (Rect,
  75.     BMPShow.Image1.Picture.Graphic);
  76. end;
  77.  
  78. procedure TPreviewForm.ScaleMinusButtonClick(Sender: TObject);
  79. begin
  80.   {decrease the size of the image}
  81.   if Scale > 1 then
  82.   begin
  83.     Scale := Scale div 2;
  84.     Label1.Caption := IntToStr (Scale);
  85.     DrawPreview;
  86.   end;
  87. end;
  88.  
  89. procedure TPreviewForm.CancelButtonClick(Sender: TObject);
  90. begin
  91.   {close (hide) the preview dialog}
  92.   Close;
  93. end;
  94.  
  95. procedure TPreviewForm.PrintButtonClick(Sender: TObject);
  96. var
  97.   Rect: TRect;
  98. begin
  99.   {compute the rectangle for the printer}
  100.   Rect.Top := 10;
  101.   Rect.Left := 10;
  102.   Rect.Right := 10 +
  103.     (BMPShow.Image1.Picture.Graphic.Width * Scale);
  104.   Rect.Bottom := 10 +
  105.     (BMPShow.Image1.Picture.Graphic.Height * Scale);
  106.  
  107.   {print the bitmap}
  108.   Printer.BeginDoc;
  109.   Printer.Canvas.StretchDraw (Rect,
  110.     BMPShow.Image1.Picture.Graphic);
  111.   Printer.EndDoc;
  112. end;
  113.  
  114. end.
  115.  
  116.  
  117.